package bsp;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;

import org.apache.hadoop.io.Writable;
import org.apache.hama.bsp.BSPPeer;
import org.apache.hama.bsp.sync.SyncException;

import util.Pair;

public abstract class CMapper<IK, IV, OK, OV, MS extends Writable> {
	/*
	 * useless
	 */
	List<Pair<String, MS>> messageBox;
	public CMapper(){
		this.messageBox = new ArrayList<Pair<String, MS>>();
	}
	
 //public abstract void map(Context<IK, IV, OK, OV, MS> context)throws IOException, SyncException, InterruptedException;

 public abstract void map(BSPPeer<IK, IV, OK, OV, MS> context)throws IOException, SyncException, InterruptedException;

	
	public void addMesg(String dist, MS msg){
		
		messageBox.add (new Pair<String, MS>(dist,msg));
	}
	
	public void sendAllMesgs(BSPPeer<IK, IV, OK, OV, MS> peer) throws IOException{
		for(Pair<String, MS> msg : messageBox){
			peer.send(msg.getFirst(), msg.getSecond());
		}
	}

}
